import time

from selenium.webdriver.common.by import By

from Base.BasePage import BasePage


class Login(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
        self.phone = (By.ID, "keywords")
        self.password = (By.ID, "password")
        self.login = (By.CLASS_NAME, "login-btn")
        self.success_ok = (By.XPATH, '//*[@id="mlayout"]/div[1]/div[1]/div/div[2]/li[1]/span')
        self.error_login = (By.XPATH, '//*[@id="ng-app"]/body/div/div[2]/div/div/div/div/div/div')
        self.error_pwd=(By.XPATH,'//*[@id="err"]/span')

    def login_succeses(self, phone, password):
        self.base_clear_input(self.phone, phone)
        self.base_clear_input(self.password, password)
        self.click_element(self.login)


        time.sleep(2)

    def assert_login(self):
        time.sleep(2)
        result = self.get_element(self.success_ok).text
        return result

    def assert_login_fail(self):
        time.sleep(2)
        result = self.get_element(self.error_login).text
        return result
    def assert_login_fail_pwd(self):
        time.sleep(1)
        result = self.get_element(self.error_pwd).text
        return result
